﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PhotoGallery.BLL;
using PhotoGallery.Model;
using System.Security.Cryptography;
public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //清除session
        Session["user"] = null;
    }
    //登录
    protected void Button1_Click(object sender, EventArgs e)
    {
        string username = this.email.Text;
        string password = Get_MD5(this.password.Text);
        LoginAction l = new LoginAction();
        User u=l.login(username, password);
        if (u == null) 
        {
            Show(Page, "密码错误！");
            return; 
        }
        else 
        { 
            Session["user"]=u;
            if (u.Role == "0")
            {
                Response.Redirect("Default.aspx");
            }
            else
                Response.Redirect("admin.aspx");
        }
    }
    public string Get_MD5(string strSource)
    {
        return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, "MD5");
    }

    public static void Show(System.Web.UI.Page page, string msg)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" +  msg.ToString() + "');</script>");
    }
}